import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import { getSyncRouter } from "@/utils/index";
import { initPager } from "@/utils/rxjs";

let instance = null;
function render(props = {}) {
  const { container } = props;
  instance = createApp(App);
  instance.use(router);
  instance.use(store);
  instance.mount(container ? container.querySelector("#app") : "#app");
}
if (window.__POWERED_BY_QIANKUN__) {
  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function bootstrap(props) {
  initPager(props.pager); // 初始化rxjs发射机
  const allRouter = getSyncRouter(props.routerData, props.name);
  allRouter.map((r) => router.addRoute(r)); // 添加路由表
}
export async function mount(props) {
  console.log("[vue-app1] props from main framework", router);
  render(props);
}
export async function unmount() {
  if (instance) {
    instance.unmount();
    instance = null;
  }
}
